﻿using System;
using System.Data;

namespace DAL
{
    public static class DalEmployee
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetEmployee(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Employee_Get");
        }
        public static DataTable GetEmployeeEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Employee_Id", id);
            return Cls.GetData("sp_Employee_Get_Edit");
        }
        public static DataTable GetAutoID(string colunmName, string tableName)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ColunmName", colunmName);
            Cls.AddParameter("@TableName", tableName);
            return Cls.GetData("sp_Create_Code");
        }
        public static DataTable GetAuto_ID(string colunmName, string tableName,string num)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ColunmName", colunmName);
            Cls.AddParameter("@TableName", tableName);
            Cls.AddParameter("@Num", num);
            return Cls.GetData("sp_Create_Code_New");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(EtEmployee obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@JobTitle_Id", obj.JobTitleId);
            Cls.AddParameter("@Bank_Id", obj.BankId);
            Cls.AddParameter("@Bank_Code", obj.BankCode);
            Cls.AddParameter("@FistName", obj.FistName);
            Cls.AddParameter("@LastName", obj.LastName);
            Cls.AddParameter("@FullName", obj.FullName);
            Cls.AddParameter("@Img", obj.Img);
            Cls.AddParameter("@Sex", obj.Sex);
            Cls.AddParameter("@Brithday", obj.Brithday);
            Cls.AddParameter("@HomePhone", obj.HomePhone);
            Cls.AddParameter("@CellPhone", obj.CellPhone);
            Cls.AddParameter("@Address", obj.Address);
            Cls.AddParameter("@Email", obj.Email);
            Cls.AddParameter("@CMND", obj.CMND);
            Cls.AddParameter("@PlaceCMND", obj.PlaceCMND);
            Cls.AddParameter("@Ethnic_Id", obj.Ethnic_Id);
            Cls.AddParameter("@Districts_Id", obj.Districts_Id);
            Cls.AddParameter("@Department_Id", obj.Department_Id);
            Cls.AddParameter("@Part_Id", obj.Part_Id);
            Cls.AddParameter("@DateCreate", obj.DateCreate);
            Cls.AddParameter("@ObjectTimekeeping", obj.ObjectTimekeeping);
            Cls.AddParameter("@EducationalLevel", obj.EducationalLevel);
            Cls.AddParameter("@Languages", obj.Languages);
            Cls.AddParameter("@Specialize", obj.Specialize);
            Cls.AddParameter("@InfomationLevel", obj.InfomationLevel);
            Cls.AddParameter("@BHXH", obj.BHXH);
            Cls.AddParameter("@DateCreateBHXH", obj.DateCreateBHXH);
            Cls.AddParameter("@Religion", obj.Religion);
            Cls.AddParameter("@NumberOfVacationDays", obj.NumberOfVacationDays);
            Cls.AddParameter("@AccountNumber", obj.AccountNumber);
            return Cls.ExecuteNonQuery("sp_tb_Employee_Insert");
        }
        public static bool Update(EtEmployee obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Employee_Id", obj.EmployeeId);
            Cls.AddParameter("@JobTitle_Id", obj.JobTitleId);
            Cls.AddParameter("@Bank_Id", obj.BankId);
            Cls.AddParameter("@Bank_Code", obj.BankCode);
            Cls.AddParameter("@FistName", obj.FistName);
            Cls.AddParameter("@LastName", obj.LastName);
            Cls.AddParameter("@FullName", obj.FullName);
            Cls.AddParameter("@Img", obj.Img);
            Cls.AddParameter("@Sex", obj.Sex);
            Cls.AddParameter("@Brithday", obj.Brithday);
            Cls.AddParameter("@HomePhone", obj.HomePhone);
            Cls.AddParameter("@CellPhone", obj.CellPhone);
            Cls.AddParameter("@Address", obj.Address);
            Cls.AddParameter("@Email", obj.Email);
            Cls.AddParameter("@CMND", obj.CMND);
            Cls.AddParameter("@PlaceCMND", obj.PlaceCMND);
            Cls.AddParameter("@Ethnic_Id", obj.Ethnic_Id);
            Cls.AddParameter("@Districts_Id", obj.Districts_Id);
            Cls.AddParameter("@Department_Id", obj.Department_Id);
            Cls.AddParameter("@Part_Id", obj.Part_Id);
            Cls.AddParameter("@DateCreate", obj.DateCreate);
            Cls.AddParameter("@ObjectTimekeeping", obj.ObjectTimekeeping);
            Cls.AddParameter("@EducationalLevel", obj.EducationalLevel);
            Cls.AddParameter("@Languages", obj.Languages);
            Cls.AddParameter("@Specialize", obj.Specialize);
            Cls.AddParameter("@InfomationLevel", obj.InfomationLevel);
            Cls.AddParameter("@BHXH", obj.BHXH);
            Cls.AddParameter("@DateCreateBHXH", obj.DateCreateBHXH);
            Cls.AddParameter("@Religion", obj.Religion);
            Cls.AddParameter("@NumberOfVacationDays", obj.NumberOfVacationDays);
            Cls.AddParameter("@AccountNumber", obj.AccountNumber);
            return Cls.ExecuteNonQuery("sp_tb_Employee_Update");
        }
        public static bool Delete(EtEmployee obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Employee_Id", obj.EmployeeId);
            return Cls.ExecuteNonQuery("sp_Employee_Get_Delete");
        }
        #endregion
    }

    public class EtEmployee
    {
        public int EmployeeId { get; set; }
        public int ? JobTitleId { get; set; }
        public int ? BankId { get; set; }
        public string BankCode { get; set; }
        public string FistName { get; set; }
        public string LastName { get; set; }
        public string FullName { get; set; }
        public string Img { get; set; }
        public string Sex { get; set; }
        public DateTime Brithday { get; set; }
        public string HomePhone { get; set; }
        public string CellPhone { get; set; }
        public string Address { get; set; }
        public string Email { get; set; }
        public string CMND { get; set; }
        public string PlaceCMND { get; set; }
        public int ? Ethnic_Id { get; set; }
        public int ? Districts_Id { get; set; }
        public int ? Department_Id { get; set; }
        public int ? Part_Id { get; set; }
        public string DateCreate { get; set; }
        public bool ObjectTimekeeping { get; set; }
        public string EducationalLevel { get; set; }
        public string Languages { get; set; }
        public string Specialize { get; set; }
        public string InfomationLevel { get; set; }
        public string BHXH { get; set; }
        public string DateCreateBHXH { get; set; }
        public string Religion { get; set; }
        public int ? NumberOfVacationDays { get; set; }
        public string AccountNumber { get; set; }
    }
}
